package cloud.zhixinglu.www.spring.boot.mapstruct.mapper;


import cloud.zhixinglu.www.spring.boot.mapstruct.enums.GenderEnum;
import cloud.zhixinglu.www.spring.boot.mapstruct.pojo.dto.StudentDTO;
import cloud.zhixinglu.www.spring.boot.mapstruct.pojo.vo.StudentVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * <p>
 * StudentMapper
 * </p>
 *
 * @author weixin
 * @date 2023/3/31 11:14
 */
@Mapper
public interface StudentMapper {

    StudentMapper INSTANCE = Mappers.getMapper(StudentMapper.class);

    /**
     * DTO转VO
     * @param student {@link StudentDTO}
     * @return {@link StudentVO}
     */
    @Mapping(source = "gender.name", target = "gender")
    @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy-MM-dd HH:mm:ss")
    StudentVO student2StudentVO(StudentDTO student);

    /**
     * 学生LIST DTO转VO
     * @param studentList {@link List<StudentDTO>}
     * @return List<StudentVO>
     */
    List<StudentVO> studentList2StudentVOList(List<StudentDTO> studentList);

    /**
     * 获取性别名称
     * @param gender {@link GenderEnum} 性别
     * @return {@link String}
     */
    default String getGenderName(GenderEnum gender) {
        return gender.getName();
    }

}
